import {
  GOODS,
  GOODS_COLUMNS,
  CLASSIFY,
  HANDLE_CLASSIFY,
  UPLOADGOODS,
  HADNLE_GOOD,
  SEARCHGOOD,
  HOTGOODS,
  SALED_TOTAL,
  GET_SOLD_NUM,
} from './api';
import { METHOD, request } from '@/utils/request';
//添加商品
export async function addGood(params) {
  return request(GOODS, METHOD.POST, params);
}
//获取商品
export async function goodsList(params) {
  return request(GOODS, METHOD.GET, params);
}
//获取单个商品
export async function goodDetails(params) {
  return request(HADNLE_GOOD, METHOD.DYNAMIC, params);
}
//搜索商品
export async function searchGood(params) {
  return request(SEARCHGOOD, METHOD.GET, params);
}
//删除商品
export async function deleteGood(params) {
  return request(HADNLE_GOOD, METHOD.DELETE, params);
}
//商品分类
export async function goodsClassify(params) {
  return request(CLASSIFY, METHOD.GET, params);
}
//删除分类
export async function deleteClassify(id) {
  return request(HANDLE_CLASSIFY, METHOD.DELETE, id);
}
//更新分类
export async function updateClassify(params) {
  return request(HANDLE_CLASSIFY, METHOD.PUT, params);
}
//添加分类
export async function addClassify(params) {
  return request(HANDLE_CLASSIFY, METHOD.POST, params);
}
//上传图片
export async function uploadImg(params, config) {
  return request(UPLOADGOODS, METHOD.POST, params, config);
}
//更新商品信息
export async function updateGood(params) {
  return request(HADNLE_GOOD, METHOD.PUT, params);
}
//热门商品
export async function getHotGoods(params) {
  return request(HOTGOODS, METHOD.GET, params);
}
//销售总额
export async function saledTotal(params) {
  return request(SALED_TOTAL, METHOD.GET, params);
}
//根据分类获取销售数量
export async function getSoldNumByClass(params) {
  return request(GET_SOLD_NUM, METHOD.GET, params);
}

export async function goodsColumns() {
  return request(GOODS_COLUMNS, METHOD.GET);
}

export default {
  goodsList,
  goodsColumns,
  goodsClassify,
  deleteClassify,
  updateClassify,
  addClassify,
  uploadImg,
  updateGood,
  addGood,
  goodDetails,
  deleteGood,
  searchGood,
  getHotGoods,
  saledTotal,
  getSoldNumByClass,
};
